package com.apress.springrecipes.shop;

import java.util.Date;
import java.util.Locale;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Main {
	public static void main(String[] args) throws Exception {
		ApplicationContext context = new ClassPathXmlApplicationContext(
				"beans.xml");
		// Product aaa = (Product) context.getBean("aaa");

		Product aaa = (Product) context.getBean("aaa");
		Product cdrw = (Product) context.getBean("cdrw");
		ShoppingCart cart1 = (ShoppingCart) context.getBean("shoppingCart");
		cart1.addItem(aaa);
		cart1.addItem(cdrw);
		System.out.println("Shopping cart 1 contains " + cart1.getItems());
		// ShoppingCart cart2 = (ShoppingCart) context.getBean("shoppingCart");
		// cart2.addItem(dvdrw);
		// System.out.println("Shopping cart 2 contains " + cart2.getItems());

		String alert = context.getMessage("alert.checkout", new Object[] { 4,
				new Date() }, Locale.US);
		System.out.println(alert);

		Cashier cashier1 = (Cashier) context.getBean("cashier1");
		cashier1.checkout(cart1);
		ProductRanking productRanking = (ProductRanking) context.getBean("productRanking");
		System.out.println("Product ranking from "
				+ productRanking.getFromDate() + " to "
				+ productRanking.getToDate());

	}
}
